package components
{
	import Classes.CLoader;
	import Classes.pi_events;
	
	import UIFree.ObjectEvent;
	
	import api_servers.pi_servers;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;

	public class pj_GenImage extends CLoader {
		private var _photoData		: Object;
		
		public function pj_GenImage(a_parent:Sprite=null) {
			super(a_parent, '', function(e: Event): void {
				parent.dispatchEvent(new ObjectEvent(pi_events.PHOTOLOADCOMPLETE, this));
			}, 0, 0, new LoaderContext(true));
			visible = false;
		}
		
		override protected function doError(e: IOErrorEvent): void {
			//super.doError(e);
			Root.dispatchEvent(new GDataEvent(GDataEvent.RESPONSEIMAGE, this));
			load(new URLRequest(pi_servers.MROOT_URL + 'empty_01.jpg'));
		}
		
		public function loadPhoto(a_data: Object): void {
			_photoData = a_data;
			load(new URLRequest(a_data.hasOwnProperty('src')?a_data.src:a_data.pic_big));
//			load(new URLRequest(a_data.pic_big?a_data.pic_big:a_data.pic));
		}
		
		public function get data(): Object {
			return _photoData;
		} 
	}
}